export default function define(Python: Blockly.BlockGenerators) {
  Python['importaispeech'] = function (block) {
    // TODO: Assemble Python into code variable.
    const code = 'import Coolguy \n\n';
    //const code = 'import sys\n'+'sys.path.append(r"/home/pi/Downloads/Coolguy.py")\n'+'import Coolguy \n\n';
    return code;
  };

  Python['api_speech'] = function (block) {
    // TODO: Assemble Python into code variable. 
    var value_api_id = Blockly.Python.valueToCode(block, 'api_id', Blockly.Python.ORDER_ATOMIC);
    var value_api_key = Blockly.Python.valueToCode(block, 'api_key', Blockly.Python.ORDER_ATOMIC);
    var value_secret_key = Blockly.Python.valueToCode(block, 'secret_key', Blockly.Python.ORDER_ATOMIC);
   // const code = 'API_ID = '+"'"+value_api_id+"'"+'\n'+'API_KEY = '+"'"+value_api_key+"'"+'\n'+'SECRET_KEY = '+"'"+value_secret_key+"'"+'\n'+'\n'+'client_speech = AipSpeech(API_ID,API_KEY,SECRET_KEY)'+'\n';
        const code = 'client_speech = Coolguy.set_client_speech("' + value_api_id + '", "' + value_api_key + '", "' + value_secret_key +'")\n'
    return code;
  };
  
  Python['api_image'] = function (block) {
    // TODO: Assemble Python into code variable. 
    var value_api_id = Blockly.Python.valueToCode(block, 'api_id', Blockly.Python.ORDER_ATOMIC);
    var value_api_key = Blockly.Python.valueToCode(block, 'api_key', Blockly.Python.ORDER_ATOMIC);
    var value_secret_key = Blockly.Python.valueToCode(block, 'secret_key', Blockly.Python.ORDER_ATOMIC);
 //   const code = 'API_ID = '+"'"+value_api_id+"'"+'\n'+'API_KEY = '+"'"+value_api_key+"'"+'\n'+'SECRET_KEY = '+"'"+value_secret_key+"'"+'\n'+'\n'+'client_image = AipImageClassify(API_ID,API_KEY,SECRET_KEY)'+'\n';
    const code = 'client_image = Coolguy.set_client_image("' + value_api_id + '", "' + value_api_key + '", "' + value_secret_key +'")\n'
    return code;
  };
  
    Python['api_ocr'] = function (block) {
    // TODO: Assemble Python into code variable. 
    var value_api_id = Blockly.Python.valueToCode(block, 'api_id', Blockly.Python.ORDER_ATOMIC);
    var value_api_key = Blockly.Python.valueToCode(block, 'api_key', Blockly.Python.ORDER_ATOMIC);
    var value_secret_key = Blockly.Python.valueToCode(block, 'secret_key', Blockly.Python.ORDER_ATOMIC);
 //   const code = 'API_ID = '+"'"+value_api_id+"'"+'\n'+'API_KEY = '+"'"+value_api_key+"'"+'\n'+'SECRET_KEY = '+"'"+value_secret_key+"'"+'\n'+'\n'+'client_image = AipImageClassify(API_ID,API_KEY,SECRET_KEY)'+'\n';
    const code = 'client_ocr = Coolguy.set_client_ocr("' + value_api_id + '", "' + value_api_key + '", "' + value_secret_key +'")\n'
    return code;
  };
    
    Python['api_face'] = function (block) {
    // TODO: Assemble Python into code variable. 
    var value_api_id = Blockly.Python.valueToCode(block, 'api_id', Blockly.Python.ORDER_ATOMIC);
    var value_api_key = Blockly.Python.valueToCode(block, 'api_key', Blockly.Python.ORDER_ATOMIC);
    var value_secret_key = Blockly.Python.valueToCode(block, 'secret_key', Blockly.Python.ORDER_ATOMIC);
 //   const code = 'API_ID = '+"'"+value_api_id+"'"+'\n'+'API_KEY = '+"'"+value_api_key+"'"+'\n'+'SECRET_KEY = '+"'"+value_secret_key+"'"+'\n'+'\n'+'client_image = AipImageClassify(API_ID,API_KEY,SECRET_KEY)'+'\n';
    const code = 'client_face = Coolguy.set_client_face("' + value_api_id + '", "' + value_api_key + '", "' + value_secret_key +'")\n'
    return code;
  };

    Python['api_default_speech'] = function (block) {
        const code = 'client_speech = Coolguy.set_client_speech()\n';
        return code;
    };

    Python['api_default_ocr'] = function (block) {
        const code = 'client_ocr = Coolguy.set_client_ocr()\n';
        return code;
    };    
    
    Python['api_default_image'] = function (block) {
        const code = 'client_image = Coolguy.set_client_image()\n';
        return code;
    };
    
    Python['api_default_face'] = function (block) {
        const code = 'client_face = Coolguy.set_client_face()\n';
        return code;
    };
  
  
  Python['synthesis'] = function (block) {
     var value_text = Blockly.Python.valueToCode(block, 'text', Blockly.Python.ORDER_ATOMIC);
     var variable_path = Blockly.Python.variableDB_.getName(block.getFieldValue('path'), Blockly.Variables.NAME_TYPE);
     const code = 'Coolguy.synthesis(client_speech,'+ value_text +', "'+ variable_path +'")\n';

     return code;
  };
  
  Python['Tuling'] = function (block) {
     var value_text = Blockly.Python.valueToCode(block, 'text', Blockly.Python.ORDER_ATOMIC);
     var variable_path = Blockly.Python.variableDB_.getName(block.getFieldValue('answer'), Blockly.Variables.NAME_TYPE);
     const code = variable_path + ' = Coolguy.Tuling('+ value_text +')\n';

     return code;
  };

    Python['synthesis1'] = function (block) {
        var value_text = Blockly.Python.valueToCode(block, 'text', Blockly.Python.ORDER_ATOMIC);
        var variable_path = Blockly.Python.variableDB_.getName(block.getFieldValue('path'), Blockly.Variables.NAME_TYPE);
        const dropdown_per = block.getFieldValue('per');
        const code = 'Coolguy.synthesis(client_speech,'+ value_text +', "'+ variable_path +'", per='+ dropdown_per +')\n';
        return code ;
    };

  Python['audio_play'] = function (block) {
      var value_name = Blockly.Python.valueToCode(block, 'text', Blockly.Python.ORDER_ATOMIC);
      var value_name1 = Blockly.Python.valueToCode(block, 'time', Blockly.Python.ORDER_ATOMIC);

      // TODO: Assemble Python into code variable.
      // const code = 'mixer.init()\n' + "mixer.music.load('" + value_name + ".mp3')\n" + 'mixer.music.play() \n' + 'time.sleep(' + value_name1 + ')\n' + 'mixer.music.stop() \n';
      const code = 'Coolguy.playAudio("'+ value_name +'.wav", ' + value_name1 + ')\n';
      return code;
   };
   
     Python['audio_play_mp3'] = function (block) {
      var value_name = Blockly.Python.valueToCode(block, 'text', Blockly.Python.ORDER_ATOMIC);
      var value_name1 = Blockly.Python.valueToCode(block, 'time', Blockly.Python.ORDER_ATOMIC);

      // TODO: Assemble Python into code variable.
      // const code = 'mixer.init()\n' + "mixer.music.load('" + value_name + ".mp3')\n" + 'mixer.music.play() \n' + 'time.sleep(' + value_name1 + ')\n' + 'mixer.music.stop() \n';
      const code = 'Coolguy.playAudio("'+ value_name +'.mp3", ' + value_name1 + ')\n';
      return code;
   };
   Python['audio_play_mp3_default'] = function (block) {
      var value_name = Blockly.Python.valueToCode(block, 'text', Blockly.Python.ORDER_ATOMIC);


      // TODO: Assemble Python into code variable.
      // const code = 'mixer.init()\n' + "mixer.music.load('" + value_name + ".mp3')\n" + 'mixer.music.play() \n' + 'time.sleep(' + value_name1 + ')\n' + 'mixer.music.stop() \n';
      const code = 'Coolguy.playAudio1("'+ value_name +'.mp3"' + ')\n';
      return code;
   };
   
   Python['audio_get'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
      var value_time = Blockly.Python.valueToCode(block, 'time', Blockly.Python.ORDER_ATOMIC);
      // TODO: Assemble Python into code variable.
      // const code = 'mixer.init()\n' + "mixer.music.load('" + value_name + ".mp3')\n" + 'mixer.music.play() \n' + 'time.sleep(' + value_name1 + ')\n' + 'mixer.music.stop() \n';
      const code = 'Coolguy.audio_get("'+ variable_result + '.wav", ' + value_time +')\n';
      return code;
   };
  
  Python['audio_recog'] = function (block) {
      var variable_path = Blockly.Python.variableDB_.getName(block.getFieldValue('voice_result'), Blockly.Variables.NAME_TYPE);
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('voice'), Blockly.Variables.NAME_TYPE);

      // TODO: Assemble Python into code variable.
      // const code = 'mixer.init()\n' + "mixer.music.load('" + value_name + ".mp3')\n" + 'mixer.music.play() \n' + 'time.sleep(' + value_name1 + ')\n' + 'mixer.music.stop() \n';
      const code = variable_path +' = Coolguy.audio_recog(client_speech,"'+ variable_result +'.wav")\n';
      return code;
   };
   
   Python['audio_recog_result'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('path'), Blockly.Variables.NAME_TYPE);
    const code = 'Coolguy.audio_recog_result(' + variable_result + ')';
    return [code, Blockly.Python.ORDER_ATOMIC];
  };
  
  Python['audio_recog_bool'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('path'), Blockly.Variables.NAME_TYPE);
    const code = 'Coolguy.audio_recog_bool(' + variable_result + ')';
    return [code, Blockly.Python.ORDER_ATOMIC];
  };
   
   Python['image_recog'] = function (block) {
      var value_path = Blockly.Python.valueToCode(block, 'path', Blockly.Python.ORDER_ATOMIC);
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('img_result'), Blockly.Variables.NAME_TYPE);

      // TODO: Assemble Python into code variable.
      // const code = 'mixer.init()\n' + "mixer.music.load('" + value_name + ".mp3')\n" + 'mixer.music.play() \n' + 'time.sleep(' + value_name1 + ')\n' + 'mixer.music.stop() \n';
      const code = variable_result +' = Coolguy.image_recog(client_image, "'+ value_path +'.jpg")\n';
      return code;
   };
   
   Python['plate_recog'] = function (block) {
      var value_path = Blockly.Python.valueToCode(block, 'path', Blockly.Python.ORDER_ATOMIC);
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('plate_result'), Blockly.Variables.NAME_TYPE);

      // TODO: Assemble Python into code variable.
      const code = variable_result +' = Coolguy.plate_recog(client_ocr, "'+ value_path +'.jpg")\n';
      return code;
   };
   
   Python['words_recog'] = function (block) {
      var value_path = Blockly.Python.valueToCode(block, 'path', Blockly.Python.ORDER_ATOMIC);
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('words_result'), Blockly.Variables.NAME_TYPE);

      // TODO: Assemble Python into code variable.
      const code = variable_result +' = Coolguy.words_recog(client_ocr, "'+ value_path +'.jpg")\n';
      return code;
   };
   
   Python['face_recog'] = function (block) {
      var value_path = Blockly.Python.valueToCode(block, 'path', Blockly.Python.ORDER_ATOMIC);
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('face_result'), Blockly.Variables.NAME_TYPE);

      // TODO: Assemble Python into code variable.
      const code = variable_result +' = Coolguy.face_recog(client_face, "'+ value_path +'.jpg")\n';
      return code;
   };
   
   Python['image_get'] = function (block) {
      var variable_path = Blockly.Python.variableDB_.getName(block.getFieldValue('img'), Blockly.Variables.NAME_TYPE);

      // TODO: Assemble Python into code variable.
      const code = 'Coolguy.image_get("'+ variable_path +'.jpg")\n';
      return code;
   };
   
     Python['image_recog_root'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
    const code = "Coolguy.img_recog_result_root(" + variable_result + ")";
    return [code, Blockly.Python.ORDER_ATOMIC];
  };
  
  Python['image_recog_keyword'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
    const code = variable_result +"['result'][0]['keyword']";
    return [code, Blockly.Python.ORDER_ATOMIC];
  };
  
  Python['plate_recog_keyword'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
    const code = variable_result +"['words_result']['number']";
    return [code, Blockly.Python.ORDER_ATOMIC];
  };
  
  Python['words_recog_keyword'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
    const code = variable_result +"['words_result'][0]['words']";
    return [code, Blockly.Python.ORDER_ATOMIC];
  };
  
  Python['face_recog_result'] = function (block) {
      var variable_result = Blockly.Python.variableDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
    const dropdown_action = block.getFieldValue('action');
    const code = 'Coolguy.face_result(' + variable_result + ', "' + dropdown_action + '")';
    return [code, Blockly.Python.ORDER_ATOMIC];
  };
  
  
  Python['wakeup_default'] = function (block) {
      var value_value = Blockly.Python.valueToCode(block, 'value', Blockly.Python.ORDER_ATOMIC);
    const code = 'Coolguy.wake_up(detected,' + value_value + ')\n'  //+'Coolguy.callbacks()\n';
    return code;
  };

  Python['define1'] = function (block) {
    let branch = Blockly.Python.statementToCode(block, 'DO');
    branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
    // const statements_name = Blockly.Python.statementToCode(block, 'NAME');
    // TODO: Assemble Python into code variable.
    const code = 'def detected():\n'+ branch;
    return code;
  };
}
